<?php

$db = new Kabupaten();
$table = "kabkota";
$kabupaten = $db->lihat($table, "idkabkota","");

$o .= '<a href="?page=addkab"><i class="icon-plus"></i> Tambah Data</a>';
if ($kabupaten) {
	
	if (isset($_GET['success']) && ($_GET['success'] == "1")) {

	$o .= '<div class="alert alert-success">
			hapus data kabupaten berhasil
			</div>';
				
	} elseif (isset($_GET['success']) && ($_GET['success'] == "0")) {
			
		$o .= '<div class="alert alert-error">
				hapus data kabupaten gagal
			   </div>';
	}
		
	$o .= '<table class="table table-striped table-bordered table-condensed">
			<tr>
				<th><center>No</th>
				<th><center>Nama Kabupaten</th>
				<th><center>Luas Wilayah</th>
				<th><center>Kepadatan Penduduk</th>
				<th><center>Tata Guna Lahan</th>
				<th><center>Topografi Wilayah</th>
				<th><center>Sumber Air Bersih</th>
				<th colspan="3"><center>Tindakan</th>
			</tr>
	
		  ';
	
	$no = 1;
	
	foreach($kabupaten as $x) {
		
		$o .= '<tr>
					<td><center>'.$no.'</td>
					<td><center>'.$x['nama_kabkota'].'</td>
					<td><center>'.$x['luas_wilayah'].'</td>
					<td><center>'.$x['kepadatan_penduduk'].'</td>
					<td><center>'.$x['tata_guna_lahan'].'</td>
					<td><center>'.$x['topografi_wilayah'].'</td>
					<td><center>'.$x['sumber_air_bersih'].'</td>
					<td><center><a href="?page=listkegiatan&idkabkota='.$x['idkabkota'].'"><i class="icon-zoom-in"></i> Lihat Kegiatan</a></td>
					<td><center><a href="?page=editkab&idkabkota='.$x['idkabkota'].'"><i class="icon-wrench"></i> Ubah</a></td>
					<td><center><a href="?page=kabupaten&action=remove&idkabkota='.$x['idkabkota'].'"><i class="icon-remove"></i> Hapus</a></td>
			  </tr>';
			  
		$no++;
		
	}

	$o .= '</table>';

} else {

	$o .= '<div class="alert alert-error">
		  <center>Data kosong</center>
		  </div>';
} 

echo $o;

if ($_GET['action'] == "remove") {

	$id = htmlentities(mysql_real_escape_string($_GET['idkabkota']));
	
	$hapuskabupaten = $db->hapus($table,$id);
	
	if ($hapussektoral) {
		?>
			<script language="javascript">
			document.location="?page=kabkota&success=1";
			</script>
		<?php
		
	} else {
		?>
			<script language="javascript">
			document.location="?page=kabkota&success=0";
			</script>
		<?php
	}
}